﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Jemgine.MapEditor
{
    partial class EditorState
    {
        public Object GetSelectionObject(Engine.Selection Selection)
        {
            switch (Selection.Type)
            {
                case Jemgine.Engine.Selection.Types.MapElement:
                    return Map.Elements[Selection.TopIndex];
                case Jemgine.Engine.Selection.Types.EntityElement:
                    return ( Map.Elements[Selection.TopIndex] as Data.EntityRecord ).AttachedElements[Selection.MiddleIndex];
                case Jemgine.Engine.Selection.Types.Vertex:
                    return ( ( Map.Elements[Selection.TopIndex] as Data.EntityRecord ).AttachedElements[Selection.MiddleIndex]
                        as Data.HasVerticies ).GetVertex(Selection.BottomIndex);
                case Jemgine.Engine.Selection.Types.Anchor:
                    return ( Map.Elements[Selection.TopIndex] as Data.Dynamic ).Anchors[Selection.MiddleIndex];
                default:
                    return null;
 
                
            }
        }

        internal Object GetTopObject(Engine.Selection Selection)
        {
            if (Selection.Type == Engine.Selection.Types.None)
                return null;
            return Map.Elements[Selection.TopIndex];
        }

        internal Object GetMiddleObject(Engine.Selection Selection)
        {
            if (Selection.Type == Jemgine.Engine.Selection.Types.EntityElement
                || Selection.Type == Jemgine.Engine.Selection.Types.Vertex)
                return ( Map.Elements[Selection.TopIndex] as Data.EntityRecord ).AttachedElements[Selection.MiddleIndex];
            return null;
        }
    }
}
